import { mapState, mapMutations } from 'vuex';
export default {
    computed: {
        ...mapState(['isGrayFilter']),
    },
    methods: {
        ...mapMutations(['setIsGrayFilter']),
        // type: 0 Appvue, 1 index
        setPageTab(pageParams, type = 0) {
            // 原始配置，在vuex的 isGrayFilter 为ture, 且接口请求回来的is_gray_filter为fasle时需要重置
            const page_data = {
                page_tab_selected_color: '#333',
                is_gray_filter: false,
                page_select_icon_ist: [
                    {
                        index: 0, //图标位置从第几个-1开始,
                        selected_icon_path: 'static/tabbar/index_a.png',
                    },
                    {
                        index: 1,
                        selected_icon_path: 'static/tabbar/categoty_a.png',
                    },
                    {
                        index: 2,
                        selected_icon_path: 'static/tabbar/cart_a.png',
                    },
                    {
                        index: 3,
                        selected_icon_path: 'static/tabbar/mine_a.png',
                    },
                ],
            };
            // 是否页面置灰
            const isGrayFill = type === 0 ? pageParams.is_gray_filter : pageParams.is_gray_filter && !this.isGrayFilter
            if (isGrayFill) {
                console.log(`${type === 0 ? 'AppVue' : 'index'}页面置灰---------------------------`);
                // 存储首页置灰参数
                this.setIsGrayFilter(pageParams.is_gray_filter);
                uni.setTabBarStyle({
                    selectedColor: pageParams.page_tab_selected_color,
                });
                pageParams.page_select_icon_ist.forEach((item, index) => {
                    uni.setTabBarItem({
                        index: item.index,
                        selectedIconPath: item.selected_icon_path,
                    });
                });
            } else if (!pageParams.is_gray_filter && this.isGrayFilter) {
                console.log(`${type === 0 ? 'AppVue' : 'index'}页面恢复非置灰---------------------------`);
                // getStore请求回来的is_gray_filter为fasle（非灰色调），并且全局vuex的isGrayFilter之前设置为true（灰色调）后重置
                this.setIsGrayFilter(pageParams.is_gray_filter);
                uni.setTabBarStyle({
                    selectedColor: page_data.page_tab_selected_color,
                });
                page_data.page_select_icon_ist.forEach((item, index) => {
                    uni.setTabBarItem({
                        index: item.index,
                        selectedIconPath: item.selected_icon_path,
                    });
                });
            }
        },
    },
};
